package com.linghang.lhonline.Util;

import com.linghang.lhonline.dataobject.Reply;
import com.linghang.lhonline.service.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

public class DeleteUtil {

    private ReplyService replyService;

    @Autowired
    public DeleteUtil(ReplyService replyService){
        this.replyService = replyService;
    }

    public void deleteReply(Reply reply){

        List<Reply> allReplyList = replyService.findByCommentId(reply.getCommentId());

        List<Reply> replyList = new ArrayList<>();
        replyList.add(reply);

        for (int i = 0; i < replyList.size(); i++) {

            for (Reply reply1 : allReplyList) {

                if (reply1.getTargetId().equals(replyList.get(i).getReplyId())) {

                    replyList.add(reply1);
                    replyService.delete(reply1);
                }
            }
        }

        replyService.delete(reply);
    }
}
